﻿using System;
using System.Collections.Generic;

namespace Marmat.Forms
{
    internal partial class CheckedComboBoxForm : PopupControl
    {
        public CheckedComboBoxForm()
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
        }

        private void BButton1_Click(object sender, EventArgs e)
        {
            CheckedComboBox box = (CheckedComboBox)this.OwnerEdit.Parent;
            var Add = new List<object>();
            var Del = new List<object>();
            for (int index = 0, loopTo = this.CheckedListBoxControl1.ItemCount - 1; index <= loopTo; index++)
            {
                var item = this.CheckedListBoxControl1.GetItemValue(index);
                if (this.CheckedListBoxControl1.GetItemChecked(index))
                    Add.Add(item);
                else
                    Del.Add(item);

            }

            foreach (object item in Del)
            {
                if (box.SelectedItems.Contains(item))
                {
                    box.SelectedItems.Remove(item);
                }
            }

            foreach (object item in Add)
            {
                if (box.SelectedItems.Contains(item) == false)
                {
                    box.SelectedItems.Add(item);
                }
            }

            box.SetValue();
            this.CloseDropDown();
        }

        private void BButton2_Click(object sender, EventArgs e)
        {
            this.CloseDropDown();
        }
    }
}